package service;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.SocketUtils;

import po.GoodsType;
import service.AdminTypeService;
import dao.*;

@Service("AdminTypeService")
@Transactional
public class AdminTypeServiceImpl implements AdminTypeService{
	@Autowired
	private GoodsTypeDao goodsTypeDao;
	
	public List<GoodsType> getAllType() {
		// TODO Auto-generated method stub
		List<GoodsType> findAllGoodsType = goodsTypeDao.findAll();
		return findAllGoodsType;
	}

	public boolean addType(String typename, Model model) {
		// TODO Auto-generated method stub
		List<GoodsType> findAllGoodsType = goodsTypeDao.findAll();
		int flag=1;
		for(GoodsType type1 : findAllGoodsType)
		{
			String type=type1.getTypename();
			if(typename.equals(type))
			{
				flag=0;
			}
		}
		if(flag==1)
		{
			goodsTypeDao.addType(typename);
			return true;
		}
		else
		{
			return false;
		}
		
	}

	public boolean deleteType(Integer id, Model model) {
		// TODO Auto-generated method stub
		if(goodsTypeDao.selectGoodsByType(id).size() > 0)
		{			
			return false;	
		}
		else
		{
			goodsTypeDao.deleteType(id);
			return true;
		}
	}

	public void updateType(Integer id, String name) {
		// TODO Auto-generated method stub
		goodsTypeDao.updateType(id, name);
	}

}
